//
//  MyPOSlistVC.m
//  NewPro
//
//  Created by 何荧红 on 2019/3/22.
//  Copyright © 2019 何荧红. All rights reserved.
//

#import "MyPOSlistVC.h"
#import "ZJScrollPageView.h"

#import "POSCanTransferVC.h"//可回拨

#import "MyPOSInactiveVC.h"//未激活
#import "ReviewInVC.h"//审核中
#import "ReviewFailureVC.h"//审核失败
#import "POShasOpenVC.h"//已开通
#import "POShasActivatedVC.h"//已激活
#import "POShasStandardVC.h"//已达标

#import "TraditionPOSListVC.h"
#import "NewOrderDetailViewController.h"

@interface MyPOSlistVC ()<ZJScrollPageViewDelegate,MyPOSInactiveVCDelegate,POShasOpenVCDelegate>

@property (nonatomic, strong) NSArray *titles;
@property (nonatomic, strong) NSArray *childVcs;
@property (nonatomic, strong) ZJScrollPageView *scrollPageView;

@end

@implementation MyPOSlistVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initCss];
}
- (void)FristReloadData{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"FriendBack" object:nil];
}

- (void)onRightBtn{
    
    POSCanTransferVC *VC = [[POSCanTransferVC alloc] init];
    [self.navigationController pushViewController:VC animated:YES];
}

- (void)setNavBar{
    
    [self setNavBarWithTitle:@"我的终端列表"];
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    //修改按钮向左偏移10 point
    [rightBtn setFrame:CGRectMake(10.0, 0.0, 44.0, 44.0)];
    [rightBtn addTarget:self action:@selector(onRightBtn) forControlEvents:UIControlEventTouchUpInside];
    [rightBtn setTitle:@"回拨" forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    //修改方法
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 44.0, 44.0)];
    [view addSubview:rightBtn];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:view];
    
    self.navigationItem.rightBarButtonItem = rightItem;
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
}
- (void)initCss{
    
    [self setNavBar];
    //必要的设置, 如果没有设置可能导致内容显示不正常
    self.automaticallyAdjustsScrollViewInsets = NO;
    ZJSegmentStyle *style = [[ZJSegmentStyle alloc] init];
    //显示滚动条
    style.showLine = YES;
    // 颜色渐变
    style.gradualChangeTitleColor = YES;
    //    style.scaleTitle = YES;
    style.titleMargin = 35;
    style.scrollLineColor = [UIColor colorWithRed:12/255.0 green:166/255.0 blue:240/255.0 alpha:1.0];
    style.normalTitleColor = [UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1.0];
    style.selectedTitleColor = [UIColor colorWithRed:12/255.0 green:166/255.0 blue:240/255.0 alpha:1.0];;
    self.titles = @[
                    @"未提交",
                    @"审核中",
                    @"审核失败",
                    @"已开通",
                    @"已激活",
                    @"已达标"
                    ];
    
    MyPOSInactiveVC *MVC = [[MyPOSInactiveVC alloc] init];
    ReviewInVC *RVC = [[ReviewInVC alloc]init];
    ReviewFailureVC *RFVC = [[ReviewFailureVC alloc]init];
    POShasOpenVC *OVC = [[POShasOpenVC alloc]init];
    POShasActivatedVC *AVC = [[POShasActivatedVC alloc]init];
    POShasStandardVC *SVC = [[POShasStandardVC alloc]init];
    self.childVcs = @[
                      MVC,
                      RVC,
                      RFVC,
                      OVC,
                      AVC,
                      SVC
                      ];
    
    // 初始化
    _scrollPageView = [[ZJScrollPageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) segmentStyle:style titles:self.titles parentViewController:self delegate:self];
    
    // 这里可以设置头部视图的属性(背景色, 圆角, 背景图片...)
    //    scrollPageView.segmentView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:_scrollPageView];
}
#pragma ZJScrollPageViewDelegate 代理方法
- (NSInteger)numberOfChildViewControllers {
    return self.titles.count;
}

- (UIViewController<ZJScrollPageViewChildVcDelegate> *)childViewController:(UIViewController<ZJScrollPageViewChildVcDelegate> *)reuseViewController forIndex:(NSInteger)index {
    UIViewController<ZJScrollPageViewChildVcDelegate> *childVc = reuseViewController;
    if (!childVc && index == 0) {
        childVc = [[MyPOSInactiveVC alloc] init];
        MyPOSInactiveVC *MVC = (MyPOSInactiveVC *)childVc;
        MVC.delegate = self;
    }
    if (!childVc && index == 1) {
        childVc = [[ReviewInVC alloc] init];
    }
    if (!childVc && index == 2) {
        childVc = [[ReviewFailureVC alloc]init];
    }
    if (!childVc && index == 3) {
        childVc = [[POShasOpenVC alloc]init];
        POShasOpenVC *PVC = (POShasOpenVC *)childVc;
        PVC.delegate = self;
    }
    if (!childVc && index == 4) {
        childVc = [[POShasActivatedVC alloc]init];
    }
    if (!childVc && index == 5) {
        childVc = [[POShasStandardVC alloc]init];
    }
//    NSLog(@"%ld-----%@",(long)index, childVc);
    return childVc;
}
- (BOOL)shouldAutomaticallyForwardAppearanceMethods {
    return NO;
}

#pragma mark MyPOSInactiveVCDelegate
- (void)CellPushNewinfo{
    [self.navigationController pushViewController:[[NewOrderDetailViewController alloc]init] animated:YES];
}
#pragma mark POShasOpenVCDelegate
- (void)OpenPushNewinfo{
    [self.navigationController pushViewController:[[NewOrderDetailViewController alloc]init] animated:YES];
}

//- (void)setTabType:(NSInteger)TabType{
//    _TabType = TabType;
//    //    self.foot.MyPOSListType = _TabType;
//}
//@property (nonatomic, assign) NSInteger TabType;
//@property (nonatomic, assign) CGFloat contentOffsetX;
//@property (nonatomic, assign) CGFloat newContentOffsetX;
//@property (nonatomic, assign) NSInteger ScrollViewPage;
//@property (nonatomic, assign) BOOL isNext;
//- (void)initCSS{
//    WS(weakself);
//    //听说这个能防止ScrollView抖动？？？
//    self.automaticallyAdjustsScrollViewInsets = NO;
//    self.edgesForExtendedLayout = UIRectEdgeNone;
//    //我不信。。。。。还真不能,不过懒得去改了
//    self.view.backgroundColor = [UIColor colorWithHexString:@"F4F4F4"];
//    ViewHeader *header = [[ViewHeader alloc]initWithDefaultString:@"我的终端列表"];
//    [self.view addSubview:header];
//    self.HeaderScroll = [[DefaultScrollView alloc]initWithMyPOSHeader];
//    [self.HeaderScroll setClikButtonIndexBlock:^(NSInteger inddx) {
//        weakself.TabType = inddx;
//        [weakself.BgScrollView setContentOffset:CGPointMake(SCREEN_WIDTH * inddx, 0) animated:NO];
//    }];
//    [self.view addSubview:self.HeaderScroll];
//
//    self.BgScrollView = [[DefaultScrollView alloc]initWithMyPOSBG];
//    self.BgScrollView.scrollEnabled = NO;
//    [self.view addSubview:self.BgScrollView];
//    [self.BgScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.view.mas_left);
//        make.top.equalTo(self.HeaderScroll.mas_bottom);
//        make.bottom.equalTo(self.view.mas_bottom);
//        make.width.mas_equalTo(SCREEN_WIDTH);
//    }];
//    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)];
//    [self.BgScrollView addGestureRecognizer:pan];
//}
//- (void)panAction:(UIPanGestureRecognizer *)pan{
//    if (pan.state == UIGestureRecognizerStateChanged) {
//        [self commitTranslation:[pan translationInView:self.BgScrollView]];
//    }
//    if (pan.state == UIGestureRecognizerStateEnded) {
//        [self ChangeScrollView:self.isNext];
//    }
//}
///** 判断手势方向  */
//- (void)commitTranslation:(CGPoint)translation {
//    CGFloat absX = fabs(translation.x);
//    CGFloat absY = fabs(translation.y);
//    // 设置滑动有效距离
//    if (MAX(absX, absY) < 10)
//        return;
//    if (absX > absY ) {
//        if (translation.x<0) {//向左滑动
//            self.isNext = YES;
//        }else{//向右滑动
//            self.isNext = NO;
//        }
//    }
//}
//- (void)ChangeScrollView:(BOOL)isNext{
//    if (self.isNext) {
//        if(self.TabType == 5){
//            [self.BgScrollView setContentOffset:CGPointMake(0, 0) animated:NO];
//        }else{
//            [self.BgScrollView setContentOffset:CGPointMake(SCREEN_WIDTH * self.TabType, 0) animated:NO];
//        }
//        [self.HeaderScroll ChangeScrollView:YES];
//    }else{
//        if(self.TabType == 0){
//            [self.BgScrollView setContentOffset:CGPointMake(SCREEN_WIDTH * 5, 0) animated:NO];
//        }else{
//            [self.BgScrollView setContentOffset:CGPointMake(SCREEN_WIDTH * self.TabType, 0) animated:NO];
//        }
//        [self.HeaderScroll ChangeScrollView:NO];
//    }
//}
@end
